package org.waddy.framework.pub.util;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;


import org.apache.log4j.Logger;
import org.waddy.framework.app.exception.AppException;
import org.waddy.framework.app.exception.SysException;



/**
 * Title: CRM <br>
 * Description: 日期时间辅助类，只能在<b>表现层</b>调用 <br>
 * Date: Jun 23, 2007 <br>
 * Copyright (c) 2007 CATTSoft <br>
 */
public class SysDateUtil {
    private static Logger log = Logger.getLogger(SysDateUtil.class);
    
    public static SimpleDateFormat datetimef = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat datetimehm = new SimpleDateFormat("yyyy-MM-dd HH:mm");

	public static SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
    
    /**
	 * 获得数据库当前时间
	 * 
	 * @return
	 * @throws SysException 
	 * @throws AppException 
	 */
	public static Date getDBDate() throws AppException, SysException {
		return SysDate.getCurrentDate();

	}
	
	/**
	 * 获得数据库当前时间字符串 精确到秒
	 * 
	 * @return
	 * @throws SysException 
	 * @throws AppException 
	 */
	public static String getDBDateTimeStr() throws AppException, SysException {
		return DateUtil.dateTime2Str(SysDate.getCurrentDate());

	}
	/**
	 * 获得数据库当前时间字符串,精确到分
	 * 
	 * @return
	 * @throws SysException 
	 * @throws AppException 
	 */
	public static String getDateTimeHMStr() throws AppException, SysException {
		return datetimehm.format(SysDate.getCurrentDate());

	}
	

    /**
     * 获取当前日期
     * 
     * @return
     */
    public static Date getCurrentDate() throws AppException, SysException {
        return SysDate.getCurrentDate();
    }

    /**
     * 获取当前数据库日期
     * 
     * @return
     * @throws AppException 
     */
    public static Date getCurrentDateFromDB() throws SysException, AppException {
        return SysDate.getCurrentDate();
    }

    /**
     * 获取当前时间
     * 
     * @return
     */
    public static Timestamp getCurrentTimestamp() throws AppException, SysException {
        return new Timestamp(SysDate.getCurrentDate().getTime());
    }

    /**
     * 获取当前数据库时间
     * 
     * @return
     * @throws AppException 
     */
    public static Timestamp getCurrentTimestampFromDB() throws SysException, AppException {
        return new Timestamp(SysDate.getCurrentDate().getTime());
    }
}
